# coding=utf-8


import logging
import subprocess
import commands
import os
import sys

log = logging.getLogger(__name__)


class ShellTool(object):

    @staticmethod
    def execute_subprocess(_cmd):
        new_env = os.environ.copy()
        r = subprocess.Popen(_cmd, shell=True, env=new_env)
        status = r.wait()
        print 'subprocess: ', status

    @staticmethod
    def execute_commands(_cmd):
        status, output = commands.getstatusoutput(_cmd)
        print 'commands: ', status, output

    @staticmethod
    def execute_os(_cmd):
        status = os.system(_cmd)
        print 'os.system: ', status


if __name__ == '__main__':
    #cmd = '/usr/local/app/uc.gzidc.area/tomcat_uschedule/bin/startup.sh'

    t = int(sys.argv[1])
    cmd = sys.argv[2]
    print 'param: ', t
    if t == 1:
        ShellTool.execute_subprocess(cmd)
    if t == 2:
        ShellTool.execute_commands(cmd)
    if t == 3:
        ShellTool.execute_os(cmd)
